package top.breezes.example.service;

import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author yuchengxin@xiaomalixing.com
 * @Date 2021/1/5 14:57
 * @Description
 */
@Slf4j
@Service
public class DemoService {

    @CircuitBreaker(name = "backendA", fallbackMethod = "backFallBack")
    public String back() {
        log.info("do something ..... ");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "success";
    }

    public String backFallBack (Exception exception) {
        log.info("back fall back error = {}",exception.getMessage());
        return "Sorry, the system is busy, please try again later.";
    }

    @CircuitBreaker(name = "backendA", fallbackMethod = "helloFallBack")
    public String hello() {
        log.info("do something hello ..... ");
        return "hello";
    }

    public String helloFallBack(Exception exception) {
        return "hello fall back";
    }

}
